<?php
class AdminRateForm extends VTNSRateForm
{
	public function configure()
    {
		$this->setWidgets(array(
                'variable_id'	 	            => new sfWidgetFormChoice(array('choices' => $this->getVariables())),
				'min_pax'                		=> new sfWidgetFormInput(),
				'max_pax'                		=> new sfWidgetFormInput(),
                'is_active'           			=> new sfWidgetFormInputCheckbox(),
				'rate_value'					=> new sfWidgetFormInput()
				));
		$this->setValidators(array(
				'rate_value'			        => new sfValidatorString(array('required' => "Giá trị chưa được nhập"))
		));
        $this->widgetSchema->setNameFormat('rate[%s]');
		$this->widgetSchema->setLabels(array(
				'variable_id'					=> 'Type of visa and Validity',
				'min_pax'						=> 'Min pax',
				'max_pax'						=> 'Max pax',
				'is_active'						=> 'Kích hoạt',
				'rate_value'					=> 'Giá trị'
		));
	}
	
	public function getVariables()
	{
		$q = Doctrine_Query::create()
				-> from('VTNSVariable v')
				-> where('v.variable_type = 0');
		$variables = $q->fetchArray();
		$var_array = array();
		foreach ($variables as $variable)
		{
			$var_array[$variable['variable_id']] = $variable['variable_name'];
		}
		return $var_array;
	}
}
?>